-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fleet: init fleet webhook and ensure single fleet per namespace #409
Conversation
✅ Deploy Preview for kurator-dev canceled.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
2e3c81c
to
300453a
Compare
300453a
to
10fbd6b
Compare
Signed-off-by: Xieql <[email protected]>
10fbd6b
to
d6f7e99
Compare
return nsLocks[ns] | ||
} | ||
|
||
func (wh *FleetWebhook) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For update, we should prebent some fields update we do not support, this need to be reviewed one by one
|
||
// Check if Fleet instance already exists in the namespace | ||
existing := &v1alpha1.Fleet{} | ||
if err := wh.Client.Get(ctx, client.ObjectKey{Namespace: in.Namespace, Name: in.Name}, existing); err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure i understand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k8s has prevented creating same fleet
|
||
// Utility function to get or create a mutex for a namespace | ||
func getOrCreateMutexForNamespace(ns string) *sync.Mutex { | ||
if _, exists := nsLocks[ns]; !exists { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data race r/w nsLocks
|
||
// Ensure only one Fleet instance in a namespace | ||
mutex := getOrCreateMutexForNamespace(in.Namespace) | ||
mutex.Lock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lock can only prevent inner-process creating, it cannot help for multi replicate scenarios.
One way as I said in the original issue, could make use of distributed lock.
maybe we can use resource quota, install fleet manager with a resourceQuota |
ok |
Given that the current design, along with the |
What type of PR is this?
/kind feature
What this PR does / why we need it:
This PR introduces validation for the Fleet custom resource using webhooks. The primary changes include:
Fleet Validation:
Cluster
,AttachedCluster
, orCustomCluster
. Any other values are considered invalid.Unit Tests:
Added unit tests to validate the logic in the Fleet webhook.
Created sample yaml files for both valid and invalid Fleet configurations to aid testing.
Here is the result of UT:
Which issue(s) this PR fixes:
part of #404
part of #336
Fixes #382
Special notes for your reviewer:
Does this PR introduce a user-facing change?: